package com.mt.api.constants.enums;

import com.mt.api.util.EnumMappingUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.Objects;

/**
 * @Author: plover
 * @Date: 2021/01/25/10:27
 * @Description:
 * 退货单状态 0-未出库 1-已退回 9-已撤销
 */
@Getter
@AllArgsConstructor
public enum OrderBackStatusEnum {
    INIT(0, "初始"),
    BACKED(1, "已退回"),
    CANCEL(9, "撤销"),
    ;

    private Integer code;
    private String name;

    private static final Map<Integer, OrderBackStatusEnum> statusEnumMap =
            EnumMappingUtil.toMappingMap(OrderBackStatusEnum.class, OrderBackStatusEnum::getCode);

    public static OrderBackStatusEnum ofCode(Integer code) {
        return statusEnumMap.get(code);
    }

    public static String nameOfCode(Integer code) {
        return Objects.nonNull(statusEnumMap.get(code)) ? statusEnumMap.get(code).getName() : StringUtils.EMPTY;
    }

}
